package com.coin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coin.domain.UserAddress;
import com.coin.service.UserAddressService;
import com.coin.mapper.UserAddressMapper;
import org.springframework.stereotype.Service;

/**
 * @author 李力
 * @description 针对表【user_address(用户钱包地址信息)】的数据库操作Service实现
 * @createDate 2025-06-07 10:16:53
 */
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress>
        implements UserAddressService {

    /**
     * @Description: 查阅用户的钱包地址
     * @Author: 李 力
     * @Date: 2025/6/7
     * @Param:
     * @return: R
     */
    @Override
    public Page<UserAddress> findByPage(Page<UserAddress> page, Long userId) {
        LambdaQueryWrapper<UserAddress> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper = queryWrapper.eq(userId != null, UserAddress::getUserId, userId);
        return page(page, queryWrapper);
    }

    /**
     * @Description: 查询用户某种币的钱包地址
     * @Author: 李 力
     * @Date: 2025/6/23
     * @Param:
     * @return: R
     */
    @Override
    public UserAddress getCoinAddress(String userId, Long coinId) {
        if (StrUtil.isEmpty(userId) || coinId == null) {
            throw new RuntimeException("参数为空");
        }
        LambdaQueryWrapper<UserAddress> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper = queryWrapper.eq(UserAddress::getUserId, Long.parseLong(userId))
                .eq(UserAddress::getCoinId, coinId.longValue());
        return getOne(queryWrapper);
    }
}




